import 'package:enjoy_plus_flutter_7/api/home.dart';
import 'package:flutter/material.dart';

class NoticeDetail extends StatefulWidget {
  const NoticeDetail({super.key});

  @override
  State<NoticeDetail> createState() => _NoticeDetailState();
}

class _NoticeDetailState extends State<NoticeDetail> {
  @override
  void didChangeDependencies() {
    // TODO: implement didChangeDependencies
    super.didChangeDependencies();

    var res = ModalRoute.of(context)?.settings.arguments;
    if (res != null) {
      // print(res['id']);
      String id = (res as Map<String, dynamic>)['id'];
      getData(id);
    }
  }

  getData(String id) async {
    var res = await getNotfiyDetailApi(id);
    // print(res);
    notifyDetail = res;
    setState(() {});
  }

  Map notifyDetail = {
    "id": "",
    "content": "",
    "title": "",
    "createdAt": "",
    "creatorName": ""
  };

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text('公告详情'),
        ),
        body: ListView(children: [
          Container(
              padding: const EdgeInsets.all(10),
              child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    // 标题
                    Text(notifyDetail['title'] ?? '',
                        style: const TextStyle(
                          fontSize: 18,
                          fontWeight: FontWeight.bold,
                        )),
                    const SizedBox(height: 10),
                    Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(notifyDetail['creatorName'] ?? '',
                              style: const TextStyle(color: Colors.grey)),
                          Text(notifyDetail['createdAt'] ?? '',
                              style: const TextStyle(color: Colors.grey))
                        ]),
                    const SizedBox(height: 10),
                    Text(notifyDetail['content'])
                    // 内容
                    //  Html(
                    //     data: notifyDetail['content'] ?? "",
                    //   )
                  ]))
        ]));
  }
}
